
function login(event) {
    let user = $("#user").val().trim();
    let pwd = $("#pwd").val().trim();

    let jsonA = {
        coding: user,
        password: pwd
    };


    $.ajaxSettings.async=false
    ajaxFormWithArgs("/dologin", "post", jsonA, function (dataA) {
        if (dataA.code == 100) {
            localStorage.setItem("token", dataA.data);
            event.preventDefault();
            $('form').fadeOut(500);
            $('.wrapper').addClass('form-success');
            setTimeout("location.href = \"/welcome\";",'2000')

        } else {
            alert("账号或密码错误！")
        }
    })
    $.ajaxSettings.async=true

    // $.ajax({
    //     url: "/dologin",
    //     type: "post",
    //     data: jsonA,
    //     dataType: "json",
    //     headers: {
    //         "token": localStorage.token
    //     },
    //     success: success,
    //     error: function (xhr) {
    //         alert("请求出错：" + xhr.status);
    //     }
    // });


}

function getName() {

        ajaxForm("view/getUserOfLogin", "get", function (dataA) {
            let id=dataA.data.id
            let jsonA={
                id:id
            }
            $.getJSON("/getPower",jsonA,function (dataB) {
            let waitToDo="    <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"我的工作平台\">&#xe6b8;</i>\n" +
                "                            <cite>我的工作平台  </cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('待办列表','list')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>待办列表</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('修改密码','yanzheng')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>修改密码</cite></a>\n" +
                "                            </li>\n"+
                "                        </ul>\n" +
                "                    </li>";
            let system=" <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"系统设置\">&#xe723;</i>\n" +
                "                            <cite>系统设置</cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('用户管理','/lq/userRole')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>用户管理</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('权限管理','getHasPower')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>权限管理</cite></a>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </li>";
            let person=" <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"人事管理\">&#xe723;</i>\n" +
                "                            <cite>人事管理</cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('人事档案管理','人事档案管理')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>人事档案管理</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('人事档案登记','人事档案登记')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>人事档案登记</cite></a>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </li>";
            let salary=" <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"薪酬管理\">&#xe723;</i>\n" +
                "                            <cite>薪酬管理</cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('薪酬标准管理','/salaryStandard')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>薪酬标准管理</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('薪酬发放管理','perindex')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>薪酬发放管理</cite></a>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </li>";
            let zhaopin=" <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"招聘管理\">&#xe726;</i>\n" +
                "                            <cite>招聘管理</cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('职位发布管理','a')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>职位发布管理</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('简历管理','/selyy')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>简历管理</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('面试管理','面试管理')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>面试管理</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('录用管理','录用管理')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>录用管理</cite></a>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </li>";
            let peixun=" <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"培训管理\">&#xe726;</i>\n" +
                "                            <cite>培训管理</cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('培训计划','培训计划')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>培训计划</cite></a>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </li>";
            let fenxi=" \n" +
                "                    <li>\n" +
                "                        <a href=\"javascript:;\">\n" +
                "                            <i class=\"iconfont left-nav-li\" lay-tips=\"数据分析\">&#xe726;</i>\n" +
                "                            <cite>数据分析</cite>\n" +
                "                            <i class=\"iconfont nav_right\">&#xe697;</i></a>\n" +
                "                        <ul class=\"sub-menu\">\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('职员明细表','职员明细表')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>职员明细表</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('职员数据综合报表','职员数据综合报表')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>职员数据综合报表</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('储备人才统计表','储备人才统计表')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>储备人才统计表</cite></a>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <a onclick=\"xadmin.add_tab('公司各体系结构分析','公司各体系结构分析')\">\n" +
                "                                    <i class=\"iconfont\">&#xe6a7;</i>\n" +
                "                                    <cite>公司各体系结构分析</cite></a>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </li>";
            let $a=$("#nav");
            $a.html("").append(waitToDo);
            let findIndex = dataB.indexOf("1");
            if (findIndex!=-1){
                $a.append(system);
            }
             findIndex = dataB.indexOf("2");
            if (findIndex!=-1){
                $a.append(person);
            }
            findIndex = dataB.indexOf("3");
            if (findIndex!=-1){
                $a.append(salary);
            }
            findIndex = dataB.indexOf("4");
            if (findIndex!=-1){
                $a.append(zhaopin);
            }
            findIndex = dataB.indexOf("5");
            if (findIndex!=-1){
                $a.append(peixun);
            }
            findIndex = dataB.indexOf("6");
            if (findIndex!=-1){
                $a.append(fenxi);
            }
        })
        $("#username").text(dataA.data.name);
    })

}

function loginOut() {

    let bo = confirm('您确定要注销吗？')

    if (bo == false) {
        return;
    }

    ajaxForm("view/loginOut", "get", function (dataA) {
        localStorage.removeItem("token")
        location.href = "/login";
    })


}

//ajax请求-无参
function ajaxForm(url, type, success) {
    $.ajax({
        url: url,
        type: type,
        dataType: "json",
        headers: {
            "token": localStorage.token
        },
        success: success,
        error: function (xhr) {
            alert("登录超时！");
            location.href="/login";
        }
    });
}

//ajax请求-带参
function ajaxFormWithArgs(url, type, args, success) {
    $.ajax({
        url: url,
        type: type,
        data: args,
        dataType: "json",
        headers: {
            "token": localStorage.token
        },
        success: success,
        error: function (xhr) {
            alert("请求出错：" + xhr.status);
        }
    });
}
